from ast import Dict
from service.das.test import JsonPlaceholderReplacer
from service.setting_service import DataDictionaryService
from views.common.translator import Translator
from views.template_page_view import BasePageTemplateView, FormItemDto, TableDataDto


class CommonSettingView(BasePageTemplateView):

    def __init__(self, parent=None):
        t = Translator()
        super().__init__("CommonSettingView", parent=parent)

    def doInitAndUpdate(self):

        # 先返回一个当前持股信息 Echat
        self.addEchatTemplate(
            "当前持股",
            "home_current_stock",
            self.exhcangeStockChatInfo,
            self.getBaseParam,
        )

        # 再返回一个当前持股信息 Table
        self.addTableTemplate("当前持股", self.getStockTableInfo, self.getBaseParam)

    # 用于返回当前的报表数据
    def exhcangeStockChatInfo(jsonData: str, params: Dict[str, str]) -> str:
        print(f"传入查询的对象信息{params}")
        replacer = JsonPlaceholderReplacer(jsonData)
        return replacer.get_modified_json()

    # 用于标记当前的查询对象
    def getBaseParam() -> Dict[str, str]:
        return {"stockCode": "100001"}

    # 用于返回当前的报表数据
    def getStockTableInfo(jsonData: str, params: Dict[str, str]) -> str:
        return TableDataDto(
            table_header=[
                "股票代码",
                "股票名称",
                "股票当前价",
                "当前盈亏比例",
                "当前风险等级",
                "操作",
            ],
            table_data=[
                ["600519", "贵州茅台", "1800.00", "+5.32%", "低风险"],
                ["000858", "五粮液", "120.00", "-2.15%", "中风险"],
                ["002304", "洋河股份", "95.50", "+1.25%", "高风险"],
            ],
            table_item_fun=[{"查看详情": view_details}],
        )
